from PyQt5.Qt import *
import sys
import os

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Shutdown")
        self.setFixedSize(400, 100)
        self.setup_ui()  # 调用函数

    def setup_ui(self):
        label = QLabel(self)
        label.setText("'y': shutdown. 'a': cancel.")
        label.setGeometry(100, 10, 300, 60)
        label.setStyleSheet("font: 20 12pt \"Microsoft YaHei\";")

        textbox = QLineEdit(self)
        textbox.resize(100, 20)
        textbox.move(100, 50)

        btn = QPushButton('Confirm !',self)
        btn.resize(100,20)
        btn.move(200,50)
        btn.setStyleSheet("background-color: rgb(220, 20, 60);"
                          "border-color: rgb(170, 150, 163);"
                          "font: 75 12pt \"Arial Narrow\";"
                          "color: rgb(126, 255, 46);")

        def clickbtn():
            textboxValue = textbox.text()
            if textboxValue == 'y':
                os.system('shutdown -s -f -t 60')
            elif textboxValue == 'a':
                os.system('shutdown -a')
            textbox.setText('')

        btn.clicked.connect(clickbtn)
        self.setWindowOpacity(0.85)
        self.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Window()
    sys.exit(app.exec_())
